<page-header-wrapper [title]="'整车代发货源'" [logo]="logo">
  <ng-template #logo>
    <button nz-button nz-tooltip nzTooltipTitle="返回上一页" (click)="goBack()">
      <i nz-icon nzType="left" nzTheme="outline"></i>
    </button>
  </ng-template>
</page-header-wrapper>
<div class="custom-style">
  <nz-card>
    <div class="card-title">货源单设置</div>
    <sf #sf1 [schema]="schema1" [button]="'none'" [ui]="ui1" [formData]="sf1data">
      <ng-template sf-template="enterpriseInfoName" let-i let-ui="ui"> {{ i.value }} </ng-template>
    </sf>
  </nz-card>

  <nz-card>
    <div class="card-title">装卸货信息<span class="tip-font">预计公里数：<em>{{ totalDistance }}km</em>，预计行程耗时：<em>{{ totalTime
          }}小时</em></span>
    </div>

    <form nz-form [formGroup]="validateForm1" role="form">
      <div nz-row [nzGutter]="24">
        <div nz-col [nzSpan]="10">
          <div *ngFor="let data1 of startInfo; let idx = index">
            <nz-form-item>
              <nz-form-label [nzSpan]="4" nzRequired>装货地</nz-form-label>
              <nz-form-control [nzErrorTip]="'请输入装货地'">
                <div class="align-center">
                  <nz-input-group [nzSuffix]="endInconTemp1">
                    <input nz-input [(ngModel)]="data1.detailedAddress" (click)="openMap('start', idx)"
                      formControlName="loadAddress{{ idx }}" placeholder="请输入装货地" readonly="true" />
                  </nz-input-group>
                  <span *ngIf="idx !== 0" style="padding: 0 10px"><i nz-icon nzType="minus-circle-o" nzTheme="outline"
                      style="color: #1890ff" (click)="subStartInfo($event, idx)"></i></span>
                  <!-- <span *ngIf="idx == 0" style="visibility:hidden;padding: 0 10px"><i nz-icon nzType="minus-circle"
                      nzTheme="outline" style="color: #d9001b" (click)="subStartInfo($event, idx)"></i></span> -->
                </div>
              </nz-form-control>
            </nz-form-item>
            <nz-form-item>
              <nz-form-label [nzSpan]="4" nzRequired>联系人</nz-form-label>
              <div nz-col [nzSpan]="20">
                <div nz-row [nzGutter]="12">
                  <nz-form-control [nzSpan]="12" [nzErrorTip]="'请输入联系人姓名'">
                    <input nz-input [(ngModel)]="data1.appUserName" formControlName="loadName{{ idx }}"
                      name="loadName{{ idx }}" maxlength="30" placeholder="请输入联系人姓名" />
                  </nz-form-control>
                  <nz-form-control [nzSpan]="12" [nzErrorTip]="'请输入联系人电话'">
                    <input nz-input [(ngModel)]="data1.contractTelephone" maxlength="11"
                      formControlName="loadPhone{{ idx }}" name="loadPhone{{ idx }}" placeholder="请输入联系人电话" />
                  </nz-form-control>
                </div>
              </div>
            </nz-form-item>
          </div>
          <div nz-row>
            <div nz-col [nzSpan]="4"></div>
            <button nz-button (click)="addStartInfo()" nzDanger>
              <i nz-icon nzType="plus"></i>
              添加装货地
            </button>
          </div>
        </div>
        <div nz-col [nzSpan]="4">
          <div class="icon-wrap">
            <span class="swap-icon" (click)="swapAddress()"></span>
          </div>
        </div>
        <div nz-col [nzSpan]="10">
          <div *ngFor="let data2 of endInfo; let idx = index">
            <nz-form-item>
              <nz-form-label [nzSpan]="4" nzRequired>卸货地</nz-form-label>
              <nz-form-control [nzErrorTip]="'请输入卸货地'">
                <div class="align-center">
                  <nz-input-group [nzSuffix]="endInconTemp1">
                    <input nz-input [(ngModel)]="data2.detailedAddress" (click)="openMap('end', idx)"
                      formControlName="unloadAddress{{ idx }}" placeholder="请输入卸货地" name="unloadAddress{{ idx }}"
                      readonly="true" />
                  </nz-input-group>
                  <span *ngIf="idx !== 0" style="padding: 0 10px"><i nz-icon nzType="minus-circle" nzTheme="outline"
                      style="color: #1890ff" (click)="subEndInfo($event, idx)"></i></span>
                  <!-- <span *ngIf="idx == 0" style="visibility:hidden;padding: 0 10px"><i nz-icon nzType="minus-circle"
                      nzTheme="outline" style="color: #d9001b" (click)="subStartInfo($event, idx)"></i></span> -->
                </div>
              </nz-form-control>
            </nz-form-item>
            <nz-form-item>
              <nz-form-label [nzSpan]="4" nzRequired>联系人</nz-form-label>
              <div nz-col [nzSpan]="20">
                <div nz-row [nzGutter]="12">
                  <nz-form-control [nzSpan]="12" [nzErrorTip]="'请输入联系人姓名'">
                    <input nz-input [(ngModel)]="data2.appUserName" maxlength="30" formControlName="unloadName{{ idx }}"
                      name="unloadAddress{{ idx }}" placeholder="请输入联系人姓名" />
                  </nz-form-control>
                  <nz-form-control [nzSpan]="12" [nzErrorTip]="'请输入联系人电话'">
                    <input nz-input [(ngModel)]="data2.contractTelephone"
                      formControlName="unloadPhone{{ idx }}" name="unloadAddress{{ idx }}" maxlength="11"
                      placeholder="请输入联系人电话" />
                  </nz-form-control>
                </div>
              </div>
            </nz-form-item>
          </div>
          <div nz-row>
            <div nz-col [nzSpan]="4"></div>
            <button nz-button (click)="addEndInfo()" nzDanger>
              <i nz-icon nzType="plus"></i>
              添加卸货地
            </button>
          </div>
        </div>
      </div>
      <div nz-row [nzGutter]="24" style="margin-top: 24px">
        <div nz-col [nzSpan]="10">
          <nz-form-item>
            <nz-form-label nzRequired [nzSpan]="4">装货时间</nz-form-label>
            <nz-form-control [nzErrorTip]="'请输入装货时间'">
              <nz-date-picker [nzShowTime]="{ nzFormat: 'HH' }" nzFormat="yyyy-MM-dd HH:00前"
                formControlName="loadingTime" [nzDisabledDate]="disabledDateStart"></nz-date-picker>
            </nz-form-control>
          </nz-form-item>
        </div>
        <div nz-col [nzSpan]="4"></div>
        <div nz-col [nzSpan]="10">
          <nz-form-item>
            <nz-form-label nzRequired [nzSpan]="4">卸货时间</nz-form-label>
            <nz-form-control [nzErrorTip]="'请输入卸货时间'">
              <nz-date-picker [nzShowTime]="{ nzFormat: 'HH' }" nzFormat="yyyy-MM-dd HH:00前"
                formControlName="unloadingTime"></nz-date-picker>
            </nz-form-control>
          </nz-form-item>
        </div>
      </div>
      <ng-template #endInconTemp1><i nz-icon nzType="environment" nzTheme="outline"></i></ng-template>
    </form>
  </nz-card>

  <nz-card>
    <div class="card-title">货物信息</div>
    <div nz-row>
      <div nz-col nzSpan="24">
        <sf #sf3 class="sf3" [schema]="schema3" [button]="'none'" [ui]="ui3" [formData]="sf3data">
          <ng-template sf-template="goodsTips" let-i let-ui="ui">
            <nz-alert class="goods_tips" nzType="warning" [nzMessage]="tpl" nzShowIcon></nz-alert>
          </ng-template>
          <ng-template #tpl>
            <span style="font-size: 14px;"> 国家法规及行政命令禁限运货物不能托运
              <a target="_blank" [queryParams]="{ type: 15 }" [routerLink]="['/passport/agreement']">《禁运物品说明》</a>
            </span>
          </ng-template>
        </sf>
      </div>
    </div>
    <sf #sf4 [schema]="schema4" [button]="'none'" [ui]="ui4" [formData]="sf4data">
      <ng-template sf-template="weight" let-i let-ui="ui">
        <nz-input-group [nzAddOnAfter]="'吨'">
          <nz-input-number [nzMax]="99999" [nzMin]="0" nzPlaceHolder="总重量，必填" type="number" [ngModel]="i.value"
            (ngModelChange)="i.setValue($event)" [nzPrecision]="2" style="width: 100%;border-radius: 4px 0 0 4px;"></nz-input-number>
        </nz-input-group>
      </ng-template>
      <ng-template sf-template="volume" let-i let-ui="ui">
        <nz-input-group [nzAddOnAfter]="'方'">
          <nz-input-number [nzMax]="99999" [nzMin]="0" nzPlaceHolder="体积" type="number" [ngModel]="i.value"
            (ngModelChange)="i.setValue($event)" [nzPrecision]="2" style="width: 100%;border-radius: 4px 0 0 4px;"></nz-input-number>
        </nz-input-group>
      </ng-template>
      <ng-template sf-template="number" let-i let-ui="ui">
        <nz-input-group [nzAddOnAfter]="'件'">
          <nz-input-number [nzMax]="99999" [nzMin]="0" nzPlaceHolder="件数" type="number" [ngModel]="i.value"
            (ngModelChange)="i.setValue($event)" [nzPrecision]="2" style="width: 100%;border-radius: 4px 0 0 4px;"></nz-input-number>
        </nz-input-group>
      </ng-template>
      <ng-template sf-template="goodsValue" let-i let-ui="ui">
        <div class="align-center">
          <nz-input-number [ngModel]="i.value" [nzMin]="0" [nzMax]="2000000" [nzStep]="0.01"
            (ngModelChange)="i.setValue($event);getInsurersPrice()" nzPlaceHolder="请输入0-2000000之间数值">
          </nz-input-number>
        </div>
      </ng-template>
    </sf>
  </nz-card>

  <nz-card>
    <div class="card-title">服务信息</div>
    <div nz-row>
      <div nz-col nzSpan="24">
        <sf #sf5 [schema]="schema5" [button]="'none'" [ui]="ui5" [formData]="sf5data">
          <ng-template sf-template="type1" let-i let-ui="ui">
            <label nz-checkbox [ngModel]="true" nzDisabled></label> &nbsp;货源曝光率 <span class="fc">+10</span>&nbsp;&nbsp;
            <label nz-checkbox [ngModel]="true" nzDisabled></label>&nbsp;车源匹配率 <span class="fc">+10</span>
          </ng-template>
          <ng-template sf-template="type2" let-i let-ui="ui">
            <label nz-checkbox [ngModel]="true" nzDisabled></label> &nbsp;货源曝光率 <span class="fc">+20</span>&nbsp;&nbsp;
            <label nz-checkbox [ngModel]="true" nzDisabled></label>&nbsp;车源匹配率 <span class="fc">+20</span>
          </ng-template>
          <ng-template sf-template="freeInsurance1" let-i let-ui="ui">
            <nz-alert nzType="warning" [nzMessage]="template1" nzShowIcon></nz-alert>
          </ng-template>
          <ng-template sf-template="freeInsurance2" let-i let-ui="ui">
            <nz-alert nzType="warning" [nzMessage]="template1" nzShowIcon></nz-alert>
          </ng-template>
          <ng-template #template1>①香港、澳门、台湾、西藏、新疆不予承保，②单次运输保额仅限200万元以内，③保险详细内容及注意事项请见<a target="_blank"
              [queryParams]="{ type: 10 }" [routerLink]="['/passport/agreement']">《保险告知函》</a></ng-template>
        </sf>
      </div>
    </div>
  </nz-card>
  <nz-card>
    <div class="card-title">补充信息</div>
    <div nz-row>
      <div nz-col nzSpan="24">
        <sf #sf6 [schema]="schema6" [button]="'none'" [ui]="ui6" [formData]="sf6data">
        </sf>
      </div>
    </div>
  </nz-card>

  <nz-card>
    <div class="card-title">运费信息</div>
    <div nz-row>
      <div nz-col nzSpan="24">
        <sf #sf7 [schema]="schema7" [button]="'none'" [ui]="ui7" [formData]="sf7data">
          <ng-template sf-template="prePay" let-i let-ui="ui">
            <nz-input-number [ngModel]="i.value" [nzMin]="0" [nzMax]="99999" [nzStep]="0.01" [nzPrecision]="2"
              nzPlaceHolder="请输入0-99999" (ngModelChange)="priceChange($event,i)" [nzFormatter]="formatterRmb"
              [nzParser]="parserRmb">
            </nz-input-number>
          </ng-template>
          <ng-template sf-template="toPay" let-i let-ui="ui">
            <nz-input-number [ngModel]="i.value" [nzMin]="0" [nzMax]="99999" [nzStep]="0.01" [nzPrecision]="2"
              nzPlaceHolder="请输入0-99999" (ngModelChange)="priceChange($event,i)" [nzFormatter]="formatterRmb"
              [nzParser]="parserRmb">
            </nz-input-number>
          </ng-template>
          <ng-template sf-template="receiptPay" let-i let-ui="ui">
            <nz-input-number [ngModel]="i.value" [nzMin]="0" [nzMax]="99999" [nzStep]="0.01" [nzPrecision]="2"
              nzPlaceHolder="请输入0-99999" (ngModelChange)="priceChange($event,i)" [nzFormatter]="formatterRmb"
              [nzParser]="parserRmb">
            </nz-input-number>
          </ng-template>
          <ng-template sf-template="subtotal" let-i let-ui="ui">{{ i.value | currency }}</ng-template>
          <ng-template sf-template="appendFee" let-i let-ui="ui">{{ i.value | currency }}（费率：{{ currentRate | number:
            '0.2-4' }}%）</ng-template>
          <ng-template sf-template="total" let-i let-ui="ui">{{ i.value | currency }}</ng-template>
          <ng-template sf-template="paymentDays" let-i let-ui="ui">
            <div nz-row class="align-center">
              <div nz-col nzSpan="6">
                <nz-input-number [ngModel]="i.value" [nzMin]="1" [nzMax]="30" [nzStep]="1"
                  (ngModelChange)="i.setValue($event)" nzPlaceHolder="请输入1-30" [nzPrecision]="0"
                  [nzPrecisionMode]="'cut'"></nz-input-number>
              </div>
              <div nz-col nzSpan="18">
                <span>&nbsp;天内支付运费</span>
              </div>
            </div>
          </ng-template>
        </sf>
      </div>
    </div>
  </nz-card>
  <nz-card class="btn-wrap">
    <div class="align-center">
      <label style="margin-right: 10px;" nz-checkbox [(ngModel)]="agreement"></label> 
      我已阅读并同意 
      <span style="color: blue;" (click)="submitConfirm('agreement')">《运输协议》</span>
  </div>
    <div class="align-center"  style="margin-top: 10px;">
      <button nz-button nzType="primary" (click)="submitConfirm('assign')" acl
        [acl-ability]="['SUPPLY-VEHICLE-RELEASE-bulkDesignate']">指派熟车</button>
      <button nz-button nzType="primary" style="margin-left: 24px" (click)="submitConfirm('publish')"
        *ngIf="type === 'add'" acl [acl-ability]="['SUPPLY-VEHICLE-RELEASE-bulkDriverOrder']">司机抢单</button>
    </div>
  </nz-card>
</div>